﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/// <summary>
/// 角色生命
/// </summary>
public class LifeCom : ECSMomentCompoentBase
{
    /// <summary>
    /// 最大生命
    /// </summary>
    public int maxLife;
    /// <summary>
    /// 当前生命
    /// </summary>
    public int life;
    /// <summary>
    /// 重生已用时间
    /// </summary>
    public int ResurgenceTimer = 0;
    /// <summary>
    /// 是否活着
    /// </summary>
    public bool iaAlive = true;
    public override ECSMomentCompoentBase DeepCopy()
    {
        throw new NotImplementedException();
    }
    /// <summary>
    /// 改变生命值，派发事件
    /// </summary>
    public int Life
    {
        get
        {
            DispatchEvent(life,life);
            return life;
        }
        set
        {
            int oldValue = life;
            life = value;
            DispatchEvent(oldValue,value);
        }
    }

    private void DispatchEvent(int oldValue, int newValue)
    {
        if (newValue>oldValue)
        {
            Entity.World.eventSystem.DispatchListener(GameUtils.GetEventKey(Entity.ID, ChanacterEventType.Recover), Entity);
        }
    }
}

